<template>
  <div>
    <!--  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">-->
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
    <head>
      <meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
      <title>美多商城-用户中心</title>
      <link rel="stylesheet" type="text/css" href="css/reset.css">
      <link rel="stylesheet" type="text/css" href="css/main.css">
    </head>
    <body>
    <div id="app" v-cloak>
      <div class="header_con">
        <div class="header">
          <div class="welcome fl">欢迎来到美多商城!</div>
          <div class="fr">
            <div class="login_info fl">
              欢迎您：<em>张 山</em>
            </div>
            <div class="login_btn fl">
              <a href="login.html">登录</a>
              <span>|</span>
              <a href="register.html">注册</a>
            </div>
            <div class="user_link fl">
              <span>|</span>
              <a href="user_center_info.html">用户中心</a>
              <span>|</span>
              <a href="cart.html">我的购物车</a>
              <span>|</span>
              <a href="user_center_order.html">我的订单</a>
            </div>
          </div>
        </div>
      </div>

      <div class="search_bar clearfix">
        <a href="index.html" class="logo fl"><img src="images/logo.png"></a>
        <div class="search_wrap fl">
          <form method="get" action="/search/" class="search_con">
            <input type="text" class="input_text fl" name="q" placeholder="搜索商品">
            <input type="submit" class="input_btn fr" name="" value="搜索">
          </form>
          <ul class="search_suggest fl">
            <li><a href="#">索尼微单</a></li>
            <li><a href="#">优惠15元</a></li>
            <li><a href="#">美妆个护</a></li>
            <li><a href="#">买2免1</a></li>
          </ul>
        </div>
      </div>

      <div class="main_con clearfix">
        <div class="left_menu_con clearfix">
          <h3>用户中心</h3>
          <ul>
            <li><a href="user_center_info.html">· 个人信息</a></li>
            <li><a href="user_center_order.html">· 全部订单</a></li>
            <li><a href="user_center_site.html" class="active">· 收货地址</a></li>
            <li><a href="user_center_pass.html">· 修改密码</a></li>
          </ul>
        </div>
        <div class="right_content clearfix">
          <div class="site_top_con">
            <a href="javascript:;" @click.prevent="chulai">新增收货地址</a>
            <span>你已创建了<b>{{total}}</b>个收货地址，最多可创建<b>{{zd}}</b>个</span>
          </div>
          <div class="site_con" v-for="i in ss">
            <div class="site_title">
              <h3>{{i.user.username}} {{ i.province}}</h3>
              <a href="javascript:;" class="edit_icon" @click.prevent="mdefault(i.id,i.user.id)"></a>
              <em v-if="i.is_default==1">默认地址</em>
              <span class="del_site">×</span>
            </div>
            <ul class="site_list">
              <li><span>收货人：</span><b>{{ i.receive }}</b></li>
              <li><span>所在地区：</span><b>{{i.city}}{{i.area}}</b></li>
              <li><span>地址：</span><b>{{i.address}}</b></li>
              <li><span>手机：</span><b>{{i.mobile}}</b></li>
              <li><span>固定电话：</span><b>{{i.tel}}</b></li>
              <li><span>电子邮箱：</span><b>{{i.email}}</b></li>
            </ul>
            <div class="down_btn">
              <a v-if="i.is_default==0" href="javascript:;" class="set_default" @click.prevent="mdefault(i.id)">设为默认</a>
              <a href="javascript:;"  class="edit_icon" @click="putmd(i.id)">编辑</a>
            </div>
          </div>
        </div>
      </div>
      <div class="footer">
        <div class="foot_link">
          <a href="#">关于我们</a>
          <span>|</span>
          <a href="#">联系我们</a>
          <span>|</span>
          <a href="#">招聘人才</a>
          <span>|</span>
          <a href="#">友情链接</a>
        </div>
        <p>CopyRight © 2016 北京美多商业股份有限公司 All Rights Reserved</p>
        <p>电话：010-****888    京ICP备*******8号</p>
      </div>

      <div class="pop_con" v-show="is_show">
        <div class="site_con site_pop">
          <div class="site_pop_title">
            <h3>新增收货地址</h3>
            <a href="javascript:;" @click.prevent="nongmei" >×</a>
          </div>
          <form>
            <div class="form_group">
              <label>收货人：</label>
              <input type="text" name="receiver" class="receiver" v-model="form.receive">
              <span class="receiver_error">请填写收货人</span>
            </div>
            <div class="form_group">
              <label>所在地区：</label>
              <select v-model="form.province" @change="addcc" >
                <option :value="i.id" v-for="i in Area" >{{i.name}}</option>
              </select>
              <select v-model="form.city" @change="addxx">
                <option :value="i.id" v-for="i in Areac" >{{i.name}}</option>
              </select>
              <select v-model="form.area">
                <option :value="i.id" v-for="i in Areax">{{i.name}}</option>
              </select>
            </div>
            <div class="form_group">
              <label>详细地址：</label>
              <input type="text" name="place" class="place" v-model="form.address">
              <span class="place_error">请填写详细地址</span>
            </div>
            <div class="form_group">
              <label>手机：</label>
              <input type="text" name="mobile" class="mobile" v-model="form.mobile">
              <span class="mobile_error">手机号有误</span>
            </div>
            <div class="form_group">
              <label>固定电话：</label>
              <input type="text" name="tel" class="tel" v-model="form.tel">
              <span class="tel_error">固定电话有误</span>
            </div>
            <div class="form_group">
              <label>邮箱：</label>
              <input type="text" name="email" class="email" v-model="form.email">
              <span class="email_error">邮箱格式有误</span>
            </div>
            <input type="button" name="" value="新 增" class="info_submit" @click="addre">
            <input type="button" name="" value="修 改" class="info_submit" @click="xiugai">
            <input type="reset" name="" value="取 消" class="info_submit info_reset">
          </form>
        </div>
        <div class="mask"></div>
      </div>

      <div class="pop_con2">
        <div class="confirm_pop">
          <div class="confirm_pop_title">
            <h3>确认删除</h3>
            <a href="javascript:;">×</a>
          </div>
          <p>您确认删除当前地址吗？</p>
          <input type="button" value="确 定" class="confirm_submit" />
          <input type="button" value="取 消" class="confirm_submit confirm_cancel"  />
        </div>
        <div class="mask"></div>
      </div>
    </div>
    </body>
    </html>
    {{form}}
  </div>
</template>

<script>
export default {
  name: "address",
  data(){
    return{
      is_show:false,
      form:{user:localStorage.getItem('mduserid')},
      Area:'',
      Areac:'',
      Areax:'',
      ss:"",
      total:'',
      zd:''
    }
  },
  methods:{
    chulai(){
      this.is_show=true
    },
    nongmei(){
      this.is_show=false
    },
    addre(){
      this.$axios.post('/addressdd/',this.form)
        .then(r=>{
          console.log(r.data)
        })
    },
    addcc(){
      this.$axios.get('/addressdd/?id='+this.form.province)
        .then(r=>{
          this.Areac=r.data.list
          this.Areax=''
          console.log(r.data)
        })
    },
    addxx(){
      this.$axios.get('/addressdd/?id='+this.form.city)
        .then(r=>{
          this.Areax=r.data.list
          console.log(r.data)
        })
    },
    getadd(){
      this.$axios.get('/addressdd/')
        .then(r=>{
          this.Area=r.data.list
          console.log(r.data)
        })
    },
    addget(){
      this.$axios.get('/addget/?uid='+localStorage.getItem('mduserid'))
        .then(r=>{
          this.ss=r.data.list
          this.total=r.data.total
          this.zd=r.data.zd
          console.log(r.data)
        })
    },
    mdefault(i,j){
      this.$axios.put('/addget/?id='+i+'&uid='+j)
        .then(r=>{
          this.addget()
          console.log(r.data)
        })
    },
    putmd(i){
      this.$axios.post('/addget/',{'id':i})
        .then(r=>{
          this.form=r.data.list
          console.log(r.data)
        })
      this.is_show=true
    },
    xiugai(){
      this.$axios.put('/addressdd/',this.form)
        .then(r=>{
          console.log(r.data)
          this.addget()
        })
    }
  },
  mounted() {
    this.getadd()
    this.addget()
  }

}
</script>

<style scoped>

</style>
